from .connect import VideoHandle, VideoVisual, VideoType
from utils.flink import FlinkBatchPusher
from fastapi import FastAPI
import uvicorn

flink = FlinkBatchPusher("localhost:9092", "video")

app = FastAPI()


@app.get("/visionModel")
async def read_root(video_type: VideoType, model_path: str, video_source: str):
    try:
        video_handle = VideoHandle(video_type, video_source,
                                   model_path)
        video_visual = VideoVisual(video_handle)
        video_visual.visual()
        return {"message": "视频流连接成功！开始实时检测！"}
    except Exception as e:
        return {"message": "视频流连接失败！请检查视频源是否正确！"}


if __name__ == "__main__":
    print("启动服务！")
    uvicorn.run(app, host="0.0.0.0", port=30000, reload=True)
